import { createRouter, createWebHashHistory } from 'vue-router'
import routerMap from './routerMap'
import { getToken } from '../utils/auth'

const Router = createRouter({
  history: createWebHashHistory(),
  routes: routerMap,
})
Router.beforeEach((to, from, next) => {
  let token = getToken()
  if(to.meta.requireAuth && !token) {
    Router.push({path: '/login'})
  }else{
    next()
  }
})
export default Router
